﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class MiniMapManager : MonoBehaviour {
    public List<BoardTile> tileList = new List<BoardTile>();
    public UISprite[] pawnObjects = new UISprite[4] ;

	// Use this for initialization
	void Start () {
		for (int i=0; i<BoardManager.Instance.boardPersonPCList.Count; i++)
		{
            if( pawnObjects[i] == null )
                pawnObjects[i] = transform.FindChild("pawn_"+(i+1)).GetComponent<UISprite>();
			pawnObjects[i].gameObject.SetActive(true);
		}
    }
	
	// Update is called once per frame
	void Update () {
        for (int i=0; i<BoardManager.Instance.boardPersonPCList.Count; i++)
        {
            foreach (BoardTile tile in tileList)
            {
                if (BoardManager.Instance.boardPersonPCList[i].curPassingBoard.boardInfo.id == tile.boardInfo.id)
                {
					if( BoardManager.Instance.boardPersonPCList[i].gameOrder <= pawnObjects.Length ) 
					{
                        Vector3 pos = tile.transform.localPosition;
                        pos.y += 20f;
						pawnObjects[BoardManager.Instance.boardPersonPCList[i].gameOrder-1].transform.localPosition = pos;
//						pawnObjects[BoardManager.Instance.boardPersonPCList[i].gameOrder-1].gameObject.SetActive(true);
					}
                    break;
                }
            }
        }

		if( CSceneManager.isSingleGame )
		{
			foreach (BoardTile tile in tileList)
			{
				if( StageManagerWrapper.objectMap.ContainsKey(StageManagerWrapper.m_BossSID) && StageManagerWrapper.objectMap[StageManagerWrapper.m_BossSID].GetComponent<BoardPerson>().curPassingBoard.boardInfo.id == tile.boardInfo.id )
				{
					pawnObjects[1].transform.localPosition = tile.transform.localPosition;
					break;
				}
			}
		}
	}
}
